package com.jarvis.spi;

import java.lang.management.ClassLoadingMXBean;
import java.lang.management.ManagementFactory;
import java.util.Iterator;
import java.util.ServiceLoader;

/**
 * TODO XXX
 *
 * @author jarvis
 * created in 2020/9/16
 */
public class SPIMain {
    public static void main(String[] args) {
        ServiceLoader<UploadCDN> uploadCDNServiceLoader = ServiceLoader.load(UploadCDN.class);
        Iterator<UploadCDN> iterator = uploadCDNServiceLoader.iterator();
        while(iterator.hasNext()){
            UploadCDN uploadCDN = iterator.next();
            uploadCDN.upload(uploadCDN.getClass().getCanonicalName());
        }
        ClassLoadingMXBean classLoadingMXBean = ManagementFactory.getClassLoadingMXBean();
        System.out.println(classLoadingMXBean.getLoadedClassCount());
        System.out.println("=================================================");
        ServiceLoader<BaseClass> baseClassServiceLoader = ServiceLoader.load(BaseClass.class);
        Iterator<BaseClass> baseIterator = baseClassServiceLoader.iterator();
        while(baseIterator.hasNext()){
            BaseClass baseClass = baseIterator.next();
            baseClass.update(baseClass.getClass().getCanonicalName());
        }
        System.out.println(classLoadingMXBean.getLoadedClassCount());
    }
}
